﻿Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Windows.Forms

Namespace Huggle.UI

    Friend Class FamilyPropertiesForm : Inherits HuggleForm

        Private LoadedViews As New List(Of Viewer)
        Private Session As Session

        Public Sub New(ByVal session As Session)
            ThrowNull(session, "session")
            Me.Session = session

            InitializeComponent()
            Size = New Size(720, 480)
        End Sub

        Private ReadOnly Property Family As Family
            Get
                Return Session.Wiki.Family
            End Get
        End Property

        Private Sub _Load() Handles Me.Load
            Icon = Resources.Icon
            Text = Msg("view-family-title", Family.Name)
            App.Languages.Current.Localize(Me)

            'Core MediaWiki views
            Views.Items.AddRange({
                Msg("view-familygeneral-title"),
                Msg("view-globalgroup-title")})

            Views.SelectedIndex = 0
        End Sub

        Private Sub Views_SelectedIndexChanged() Handles Views.SelectedIndexChanged
            Select Case Views.SelectedItem.ToString
                Case Msg("view-familygeneral-title")
                    If Not LoadedViews.ContainsInstance(Of GeneralFamilyView)() Then LoadedViews.Add(New GeneralFamilyView(Session))
                    ViewInstance(Of GeneralFamilyView)()

                Case Msg("view-globalgroup-title")
                    If Not LoadedViews.ContainsInstance(Of GlobalGroupView)() Then LoadedViews.Add(New GlobalGroupView(Session))
                    ViewInstance(Of GlobalGroupView)()
            End Select
        End Sub

        Private Sub ViewInstance(Of T As Viewer)()
            ViewContainer.Controls.Clear()
            ViewContainer.Controls.Add(LoadedViews.FirstInstance(Of T))
        End Sub

    End Class

End Namespace